package mips.structure;

import llvmir.value.Value;
import llvmir.value.constants.Constant;
import llvmir.value.constants.ConstantString;

public class MipsGV {
    String name;
    Constant value;

    public MipsGV(String name, Value value) {
        this.name = name;
        this.value = (Constant) value;
    }

    @Override
    public String toString() {
        if (value instanceof ConstantString) {
            ConstantString cs = (ConstantString) value;
            // 如果是以.str.开头的字符串，说明是输出用的字符串
            if (name.startsWith(".str.")) {
                return ".align 2\n" + name + ": " + cs.toMips();
            } else {
                return name + ": " + cs.toMipsForInt();
            }

        }
        return name + ": " + value.toMips();
    }

}
